const { DataTypes } = require('sequelize');
const sequelize = require('../../config/db');
const User = require('./User');

const Order = sequelize.define('orders', {
  id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
  user_id: { type: DataTypes.INTEGER, references: { model: User, key: 'id' } },
  total_price: { type: DataTypes.DECIMAL(10,2) },
  status: { type: DataTypes.STRING, defaultValue: '进行中' },
  address: { type: DataTypes.STRING },
  contact: { type: DataTypes.STRING },
  remark: { type: DataTypes.STRING },
  phone: { type: DataTypes.STRING },
  created_at: { type: DataTypes.DATE, defaultValue: DataTypes.NOW }
}, {
  tableName: 'orders',
  timestamps: false
});

Order.belongsTo(User, { foreignKey: 'user_id', as: 'user' });

module.exports = Order;
